package treeedit;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.net.URL;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JProgressBar;
import javax.swing.JWindow;

public class Splash extends JWindow implements MouseListener,Runnable
{
	
	private JProgressBar bar = new JProgressBar();
	private Thread thread = null;
	
	public Splash(String filename, Frame f)
    {
        super(f);

        URL url = Splash.class.getResource(filename);
        
		JLabel l = new JLabel(new ImageIcon(url));
        getContentPane().add(l, BorderLayout.CENTER);
        getContentPane().add(bar,BorderLayout.SOUTH);
        pack();
        Dimension screenSize =
          Toolkit.getDefaultToolkit().getScreenSize();
        Dimension labelSize = l.getPreferredSize();
        setLocation(screenSize.width/2 - (labelSize.width/2),
                    screenSize.height/2 - (labelSize.height/2));
        addMouseListener(this);
        
        //run();
    }
	
	
	

	public void mouseClicked(MouseEvent arg0) 
	{
		setVisible(false);
		synchronized (this) {
			notify();
			
		}
		dispose();
	}

	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}




	public void run() 
	{
		thread = Thread.currentThread();
		setVisible(true);
		bar.setIndeterminate(true);
		try
		{
			synchronized (this)
			{
				wait();
			}
			Thread.sleep(1000);

		}catch(InterruptedException e)
		{
		}
		
		setVisible(false);
		dispose();
		
	}
	
	

}
